<!DOCTYPE html>
<html>

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<meta id="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
		<meta name="apple-themes-web-app-capable" content="yes">
		<meta content="yes" name="apple-mobile-web-app-capable">
		<meta content="black" name="apple-mobile-web-app-status-bar-style">
		<meta content="telephone=no" name="format-detection">
		<meta content="email=no" name="format-detection">
		<meta name="format-detection" content="telephone=no">
		<title>修改支付密码</title>
		<link rel="stylesheet" href="${s.base}/mobile/css/main.css" type="text/css" media="all">
	</head>

	<body> 
		<header id="header">
			<div class="header_con">
            	<a href="javascript:history.go(-1);"><span></span></a> 
                <div class="top_tit">修改支付密码</div>
			</div>
		</header>

		<div id="content_div">
             <div class="pay_02">
              <p class="border_bottom">登录名：<input type="text" id="phone" style="width: 80%;height: 0.8rem;line-height: 0.8rem;border: 0px; text-align: left;" placeholder="请输入注册手机号" /></p>
               <p class="border_bottom">验证码：
				   <input type="text" id="verifyCode" style="width: 50%;height: 0.8rem;line-height: 0.8rem;border: 0px; text-align: left;" placeholder="请输入验证码" />
				   <input type="button" id="verify" style="width: 27%;height: 0.6rem;line-height: 0.6rem;border: 0px; border-radius:5px; border:1px solid #F00; background:#FFF;" value="获取验证码"/>
			   </p>
				 <input type="hidden" id="oldVerifyCode" />

               <p class="border_bottom" <#if type!='1'>style="display: none;"</#if>>支付密码：
				 <input type="password" id="payPassword" style="width: 70%;height: 0.8rem;line-height: 0.8rem;border: 0px; text-align: left;" placeholder="请输入支付密码" />
				</p>

				 <p class="border_bottom" <#if type!='2'>style="display: none;"</#if>>登录密码：
				 <input type="password" id="password" style="width: 70%;height: 0.8rem;line-height: 0.8rem;border: 0px; text-align: left;" placeholder="请输入登录密码" />
				 </p>
             </div>
             
              <div class="pay_04 margin_top_1"><a href="javascript:void(0)" id="updatePws" class="ui-btn">立即修改</a></div>
             
        
      </div>	
        <!--底部-->
		<!--底部结束-->
		<script src="${s.base}/mobile/js/jquery-1.7.2.min.js"></script>
		<script type="text/javascript" src="${s.base}/mobile/js/common.js"></script>
		<script type="text/javascript" src="${s.base}/js/layer/layer.js"></script>
		<script type="text/javascript" src="${s.base}/js/base/commont.js"></script>

		<script type="text/javascript">
            var memberId='${memberId}';
            $("#updatePws").on("click",function () {
                var type='${type}';
                var phoneOld = '${member.phone}';
                var phone = $("#phone").val();
                var verifyCode = $("#verifyCode").val();
                var oldVerifyCode = $("#oldVerifyCode").val();
                var payPassword = $("#payPassword").val();
                var payReg = /^\d{6}$/;
                var password = $("#password").val();
                if (phone == null || phone == ""){
                    layer.alert("请输入手机号");
                    return false;
                }
                if (phone != phoneOld){
                    layer.alert("您输入的手机号与注册手机号不符！");
                    return false;
				}
                /*if (verifyCode == null || verifyCode == ""){
                    layer.alert("请输入验证码");
                    return false;
                }
                if (oldVerifyCode == null || oldVerifyCode == ""){
                    layer.alert("您未获取到验证码，请会重新发送");
                    return false;
                }
                if (oldVerifyCode != verifyCode){
                    layer.alert("您输入的验证码有错，请重新输入！");
                    return false;
                }*/
                if (type=="1" && (payPassword == null || payPassword == "")){
                    layer.alert("请输入支付密码");
                    return false;
                } else {
                    if (!payReg.test(payPassword)){
                        layer.alert("请输入6位纯数字的支付密码");
                        return false;
					}
				}
                if (type=="2" && (password == null || password == "")){
                    layer.alert("请输入登录密码");
                    return false;
                }

                $.ajax({
                    type: "POST",
                    url: "/phone/myUpdateNews?memberId="+memberId,
                    data: {"id":memberId,"payPassword":payPassword,"password":password},
                    success: function(result){
                        if(1==result.returnInfo.state){
                            showLayerAlertNoRefre("修改成功");
                            window.location.href="${s.base}/phone/mySet?memberId="+memberId;
                        }else{
                            showLayerAlertNoRefre(result.returnInfo.errorMsg);
                        }
                    },
                    error: function(result){
                        showLayerAlertNoRefre(result);
                    }
                });
            });

            $("#verify").on("click",function () {
                timer(60);
                $.post("/phone/verifyCode",{
                    memberId : memberId
                },function(result){
                    if(1==result.returnInfo.state){
                        console.log(result);
                        $("#oldVerifyCode").val(result.returnInfo.errorMsg);
                        layer.alert("发送成功！");
                    }else{
                        layer.alert(result.returnInfo.errorMsg+"，请重试！");
                    }
                },"json");
            });

            function timer(time) {
                var btn = $("#verify");
                btn.attr("disabled", true);  //按钮禁止点击
                btn.val(time <= 0 ? "获取验证码" : ("" + (time) + "秒后可发送"));
                var hander = setInterval(function() {
                    if (time <= 0) {
                        clearInterval(hander); //清除倒计时
                        btn.val("获取验证码");
                        btn.attr("disabled", false);
                        return false;
                    }else {
                        btn.val("" + (time--) + "秒后可发送");
                    }
                }, 1000);
            }
		</script>
	</body>
</html>